#include "togglebutton.h"

ToggleButton::ToggleButton(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(280, 220))
{
	wxPanel *panel = new wxPanel(this, wxID_ANY);
	colour = new wxColour(0x00, 0x00, 0x00);

	m_tgb_r = new wxToggleButton(panel, ID_TB_R, wxT("Red"),	wxPoint(20, 20));
	m_tgb_g = new wxToggleButton(panel, ID_TB_G, wxT("Green"),	wxPoint(20, 70));
	m_tgb_b = new wxToggleButton(panel, ID_TB_B,wxT("Blue"),	wxPoint(20, 120));

	Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &ToggleButton::OnToggleRed,	this, ID_TB_R);
	Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &ToggleButton::OnToggleGreen,	this, ID_TB_G);
	Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &ToggleButton::OnToggleBlue,	this, ID_TB_B);

	m_panel = new wxPanel(panel, wxID_NEW, wxPoint(150, 20), wxSize(110, 110), wxSUNKEN_BORDER);
	m_panel->SetBackgroundColour(*colour);
}

void ToggleButton::OnToggleRed(wxCommandEvent& WXUNUSED(event))
{
	unsigned char r = colour->Red() ? 0x00 : 0xff;
	unsigned char g = colour->Green();
	unsigned char b = colour->Blue();

	colour->Set(r, g, b);
	m_panel->SetBackgroundColour(*colour);
	Refresh();
}

void ToggleButton::OnToggleGreen(wxCommandEvent& WXUNUSED(event))
{
	unsigned char r = colour->Red();
	unsigned char g = colour->Green() ? 0x00 : 0xff;
	unsigned char b = colour->Blue();

	colour->Set(r, g, b);
	m_panel->SetBackgroundColour(*colour);
	Refresh();
}

void ToggleButton::OnToggleBlue(wxCommandEvent& WXUNUSED(event))
{
	unsigned char r = colour->Red();
	unsigned char g = colour->Green();
	unsigned char b = colour->Blue() ? 0x00 : 0xff;

	colour->Set(r, g, b);
	m_panel->SetBackgroundColour(*colour);
	Refresh();
}
